﻿@functions  {

    HtmlString showPageItem(int index, string link, string text)
    {
        
        if (Model.PageIndex == index)
        {
            return new HtmlString(string.Format("<li class='currentGalleryPage'>{0}</li>", text));
        }
        else
        {
            return new HtmlString(string.Format("<li><a href='{0}?galleryPage={1}'>{2}</a></li>", link, index, text));
        }        
    }
}

@{    
    @:<div class="simpleGalleryPagerContainer">        
    if (Model.PageCount > 1)
    {
        string link = Request.Url.ToString().Split('?')[0];
        
        @:<ul class="simpleGalleryPager">
            if (!Model.IsFirstPage)
            {
                @:<li class="goToAction goToFirst"><a href="@link?galleryPage=1">@T("<<")</a></li>
                @:<li class="goToAction goToPrevious"><a href="@link?galleryPage=@(Model.PageIndex - 1)">@T("<")</a></li>                            
            }

            for (int i = Model.FirstItemIndex; i <= Model.LastItemIndex; i++)
            {
                string text = i.ToString();

                if ((i == Model.FirstItemIndex && i != 1) || (i == Model.LastItemIndex && i != Model.PageCount))
                {
                    text = "...";
                }
                                
                @showPageItem(i, link, text);
            }

            if (!Model.IsLastPage)
            {
                @:<li class="goToAction goToNext"><a href="@link?galleryPage=@(Model.PageIndex + 1)">@T(">")</a></li>            
                @:<li class="goToAction goToLast"><a href="@link?galleryPage=@(Model.PageCount)">@T(">>")</a></li>
            }
        @:</ul>
    }
    @:</div>
}
